# _*_ coding: UTF-8 _*_
# @Time     : 2021/11/3 19:20
# @Author   : 郑鲁明
# @Site     : http://www.hzdledu.cn/
# @File     : personner_report.py
# @Software : PyCharm
from selenium.webdriver.support.wait import WebDriverWait  # 等待类
from selenium.webdriver.support import expected_conditions  # 等待条件
from selenium.webdriver.common.by import By  # 定位符
from selenium import webdriver
import time
from selenium.webdriver.common.action_chains import ActionChains
from selenium.webdriver.support.select import Select
from selenium.webdriver.common.keys import Keys

class PersonnerReport():

    def __init__(self,driver):
        # 导航栏—统计报表
        self.nav_Stat_report = (By.XPATH,'//*[@id="root"]/section/aside/div/ul/li[5]/div')
        # 导航栏-统计报表—招聘报表
        self.nav_recruit_report = (By.XPATH,'//*[@id="report$Menu"]/li/div')
        # 导航栏-统计报表-招聘报表-人事报表
        self.nav_personnner_report = (By.XPATH,'//*[@id="saleReport$Menu"]/li[1]')
        # 查询按钮
        self.query_button = (By.XPATH,'//*[@id="root"]/section/section/main/div/div[1]/button')

        # 查询条件界面 查询功能
        self.query_funtion_botton = (By.XPATH,'/html/body/div[2]/div/div[2]/div/div[2]/div[3]/div/button[2]')
        # 查询条件界面 关闭功能
        self.query_close_botton = (By.XPATH,'//*[@class="ant-modal-close-x"]')
        # 查询条件界面点击开始时间
        self.query_startime = (By.XPATH,'//*[@id="startTimeDistribute"]/div[1]/input')
        # 查询条件界面输入开始时间
        self.query_input_startime = (By.XPATH,'//*[@class="ant-calendar-date-input-wrap"]/input')
        # 查询条件界面点击结束时间
        self.query_endtime = (By.XPATH,'//*[@id="endTimeDistribute"]/div[1]/input')
        # 查询条件界面输入结束时间
        self.query_input_endtime = (By.XPATH,'//*[@class="ant-calendar-date-input-wrap"]/input')
        # 查询条件界面选择产品线
        self.query_product_line = (By.XPATH,'//*[@id="productId"]/div/div/div')
        # 查询条件界面重置按钮
        self.query_reset_botton = (By.XPATH,'//*[@class="ant-modal-footer"]/div/button')

        self.driver = driver
        self.wait = WebDriverWait(driver,30)

        # 测试时去除
        # self.driver = webdriver.Chrome()

    # 切换至人事报表
    def jump_to(self):
        try:
            time.sleep(0.5)
            self.wait.until(expected_conditions.presence_of_element_located(self.nav_Stat_report))
            self.driver.find_element(*self.nav_Stat_report).click()
            time.sleep(0.5)
            self.wait.until(expected_conditions.presence_of_element_located(self.nav_recruit_report))
            self.driver.find_element(*self.nav_recruit_report).click()
            time.sleep(0.5)
            self.wait.until(expected_conditions.presence_of_element_located(self.nav_personnner_report))
            self.driver.find_element(*self.nav_personnner_report).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/人事报表错误.png')
            raise e

    # 查询按钮功能
    def query_open(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_button))
            self.driver.find_element(*self.query_button).click()
            time.sleep(1)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面弹出错误.png')
            raise e

    # 查询条件界面的查询按钮功能
    def query_funtion(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_funtion_botton))
            self.driver.find_element(*self.query_funtion_botton).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询功能弹出错误.png')
            raise e

    # 查询条件界面的关闭
    def query_close(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_close_botton))
            self.driver.find_element(*self.query_close_botton).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面关闭错误.png')
            raise e

    # 查询条件界面的开始时间输入
    def starttimequery(self,starttime):
        try:
            time.sleep(1)
            self.wait.until(expected_conditions.presence_of_element_located(self.query_startime))
            self.driver.find_element(*self.query_startime).click()
            self.wait.until(expected_conditions.presence_of_element_located(self.query_input_startime))
            self.driver.find_element(*self.query_input_startime).send_keys(starttime)
            self.driver.find_element(*self.query_input_startime).send_keys(Keys.ENTER)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面开始时间输入错误.png')
            raise e

    # 查询条件界面的结束时间输入
    def endtimequery(self,endtime):
        try:
            time.sleep(1)
            self.wait.until(expected_conditions.presence_of_element_located(self.query_endtime))
            self.driver.find_element(*self.query_endtime).click()
            self.wait.until(expected_conditions.presence_of_element_located(self.query_input_endtime))
            self.driver.find_element(*self.query_input_endtime).send_keys(endtime)
            self.driver.find_element(*self.query_input_endtime).send_keys(Keys.ENTER)
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面开始时间输入错误.png')
            raise e

    # 查询条件界面的产品线选择
    def query_produte_select(self,produte_line):
        # 选择产品线
        self.query_product_line_select = (By.XPATH,f'//li[text()="{produte_line}"]')
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_product_line))
            self.driver.find_element(*self.query_product_line).click()
            self.wait.until(expected_conditions.presence_of_element_located(self.query_product_line_select))
            self.driver.find_element(*self.query_product_line_select).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面产品线选择错误.png')
            raise e

    def query_reset(self):
        try:
            self.wait.until(expected_conditions.presence_of_element_located(self.query_reset_botton))
            self.driver.find_element(*self.query_reset_botton).click()
        except Exception as e:
            self.driver.get_screenshot_as_file('./log/查询条件界面重置按钮错误.png')
            raise e